/* 当只查看某角色用户单选按钮状态改变时，获取新的数据 */
function onlyRoleChange() {
    var key = $("input[name = 'onlyRole_radio']").filter(":checked").val();
    console.log("--call onlyRoleChange, " + key);
    /* 因为查询条件变动，所以需要显示页面也需要重置到第一页 */
    userManView(key, 1);
}

/* 显示第几页 */
function showPage(current, pages, onlyRole) {
    console.log("---call showPage - " + current + "," + onlyRole);
    if(current >= 1 || current <= pages){
        /* 合法的页面值，发起调用 */
        userManView(onlyRole, current);
    }
}

/* 用户添加页面 */
function userAddView() {
    console.log("---call userAddView");
    /* 发起调用 */
    call(null, source, TYPE_ADD_OR_EDIT_VIEW, YS_VIEW, "", USER_TASK, token);
}

/* 用户编辑页面 */
function userEditView(uid) {
    console.log("---call userEditView");
    /* 发起调用 */
    call(null, source, TYPE_ADD_OR_EDIT_VIEW, YS_VIEW, uid + "", USER_TASK, token);
}

/* 删除一个用户 */
function userRemove(uid) {
    console.log("---call userRemove");
    // 询问用户确认
    var b = confirm("数据无价，你想好了？");
    if(b){
        /* 发起调用 */
        call(null, source, TYPE_REMOVE, YS_VIEW, uid + "", USER_TASK, token);
    }

    return false;
}

function userSaveOrUpdate() {
    /* 封装用户数据成json */
    var uinfo = {};
    uinfo.nickname = $("input[name = 'uinfo.nickname']").val();
    uinfo.phone = $("input[name = 'uinfo.phone']").val();
    var user = {};
    user.uid = $("input[name = 'uid']").val();
    user.username = $("input[name = 'username']").val();
    user.password = $("input[name = 'password']").val();
    user.locked = Boolean($("input[name = 'locked']:checked").val() === "true");
    user.enabled = Boolean($("input[name = 'enabled']:checked").val() === "true");
    user.uinfo = uinfo;
    console.log("---call userSaveOrUpdate");
    console.log(user);

    /* 发起调用 */
    call(null, source, TYPE_ADD_OR_UPDATE, YS_VIEW, JSON.stringify(user), USER_TASK, token);
    return false;
}


